import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hook_up_rent/routes/index.dart';
import 'package:hook_up_rent/store/modal.dart';
import 'package:hook_up_rent/store/store.dart';

class Header extends StatefulWidget {
  const Header({Key key}) : super(key: key);

  @override
  _HeaderState createState() => _HeaderState();
}

class _HeaderState extends State<Header> {
  _generatorTextStyle(double fontSize) {
    return TextStyle(color: Colors.white, fontSize: fontSize);
  }

  final LoginStateController loginStateController =
      Get.put(LoginStateController());

  @override
  Widget build(BuildContext context) {
    final Rx<HeaderInfo> headerInfo = loginStateController.userInfo;
    return Container(
      height: 95.0,
      color: Colors.green,
      padding: EdgeInsets.only(left: 20, top: 10),
      child: Row(
        children: [
          // 头像
          Container(
            width: 65.0,
            height: 65.0,
            child: Obx(() => CircleAvatar(
                  backgroundImage: NetworkImage(headerInfo.value.pic),
                )),
          ),
          // 字体
          Padding(
              padding: const EdgeInsets.all(17.0),
              // 应该使用类比较好了 getfind
              child: Obx(() =>
                  _buildIsloginInfo(context, headerInfo, loginStateController)))
        ],
      ),
    );
  }

  _buildIsloginInfo(BuildContext context, Rx<HeaderInfo> headerInfo,
      LoginStateController loginStateController) {
    if (loginStateController.loginState.value) {
      // 手势
      // print("执行54${loginStateController.loginState.value}");
      return GestureDetector(
        onTap: () {
          Navigator.of(context).pushNamed("settings");
        },
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              headerInfo.value.nickName,
              style: _generatorTextStyle(20),
            ),
            Text(headerInfo.value.explain, style: _generatorTextStyle(14))
          ],
        ),
      );
    } else {
      return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        Row(
          children: [
            GestureDetector(
              child: Text(
                headerInfo.value.onLoginInfo[0],
                style: _generatorTextStyle(20),
              ),
              onTap: () {
                Navigator.pushNamed(context, MyRoutes.login);
              },
            ),
            Text(
              "/",
              style: _generatorTextStyle(20),
            ),
            GestureDetector(
              child: Text(
                headerInfo.value.onLoginInfo[1],
                style: _generatorTextStyle(20),
              ),
              onTap: () {
                Navigator.pushNamed(context, MyRoutes.register);
              },
            )
          ],
        ),
        Text(
          headerInfo.value.explain,
          style: _generatorTextStyle(14),
        )
      ]);
    }
  }
}
